package com.gzz.orchid.common.boot.mybatis.conditices.rule;

import java.text.MessageFormat;

/**
 * @author higmd
 */
public class LikeRegular extends AbstractRegular {
    private Object value;
    public enum SCOPE {
        LEFT, RIGHT, BOTH
    }
    private final SCOPE scope;
    public LikeRegular(String fieldName,SqlSymbol symbol, SqlSymbol previous, Object value, SCOPE scope ) {
        super(fieldName, symbol, previous);
        this.scope = scope;
        this.value = value;
    }

    @Override
    public String resolveExpression() {
        if (scope == SCOPE.LEFT) {
            return MessageFormat.format(" {0}  like ''%{1}''", this.fieldName, this.value);
        } else if (scope == SCOPE.RIGHT) {
            return MessageFormat.format(" {0} like ''{1}%''",  this.fieldName, this.value);
        } else {
            return MessageFormat.format(" {0} like ''%{1}%''", this.fieldName, this.value);
        }
    }
}
